// 查询商品列表
import {gql} from "@apollo/client";

export const GET_PRODUCTS = gql`
query MyQuery($cursor: String, $limit: Int) {
  product {
    productList(limit: $limit, cursor: $cursor) {
      hasNext
      nextCursor
      products {
        coverAddr
        createTime
        description
        detailAddr
        id
        price
        rate
        specifications {
          createTime
          id
          item
          productId
          updateTime
          value
        }
        status
        stockpile
        stockpileFrozen
        title
        updateTime
      }
    }
  }
}
`;

// 根据ID查询单个商品
export const GET_PRODUCT_BY_ID = gql`
query MyQuery($id: Int) {
  product {
    productById(id: $id) {
      coverAddr
      createTime
      description
      detailAddr
      price
      id
      rate
      specifications {
        createTime
        id
        item
        productId
        updateTime
        value
      }
      status
      stockpile
      stockpileFrozen
      title
      updateTime
    }
  }
}
`;

export const CREATE_PRODUCT = gql`
mutation MyMutation(
  $specifications: [ProductSpecificationInput!]
  $coverAddr: String
  $description: String
  $detailAddr: String
  $price: String
  $rate: Float
  $status: String
  $stockpile: Int
  $title: String
) {
  product {
    createProduct(
      input: {
        title: $title
        price: $price
        rate: $rate
        detailAddr: $detailAddr
        stockpile: $stockpile
        status: $status
        coverAddr: $coverAddr
        description: $description
        specifications: $specifications
      }
    ) {
      coverAddr
      createTime
      description
      detailAddr
      id
      price
      rate
      specifications {
        createTime
        id
        item
        productId
        updateTime
        value
      }
      status
      stockpile
      stockpileFrozen
      title
      updateTime
    }
  }
}
`;

export const DELETE_PRODUCT = gql`
mutation MyMutation($id: Int) {
  product {
    deleteProduct(id: $id)
  }
}
`;

export const UPDATE_PRODUCT = gql`
mutation MyMutation(
  $id: Int
  $rate: Float
  $price: String
  $detailAddr: String
  $description: String
  $coverAddr: String
  $status: String
  $stockpile: Int
  $title: String
  $specifications: [UpdateProductSpecificationInput!]
) {
  product {
    updateProduct(
      id: $id
      input: {
        coverAddr: $coverAddr
        description: $description
        detailAddr: $detailAddr
        price: $price
        rate: $rate
        specifications: $specifications
        status: $status
        stockpile: $stockpile
        title: $title
      }
    ) {
      coverAddr
      createTime
      description
      detailAddr
      id
      price
      rate
      specifications {
        createTime
        id
        item
        productId
        updateTime
        value
      }
      status
      stockpile
      stockpileFrozen
      title
      updateTime
    }
  }
}
`;

export const fetchQueryProductList = gql`
query MyQuery2(
  $keyword: String
  $limit: Int
  $cursor: String
) {
  product {
    queryProductList(keyword: $keyword, limit: $limit, cursor: $cursor) {
      hasNext
      nextCursor
      products {
        coverAddr
        createTime
        detailAddr
        description
        id
        rate
        price
        specifications {
          createTime
          item
          id
          productId
          value
          updateTime
        }
        stockpileFrozen
        title
        status
        stockpile
        updateTime
      }
    }
  }
}
`;
